home *** CD-ROM | disk | FTP | other *** search
/ Hardcore Visual Basic 5.0 (2nd Edition) / Hardcore Visual Basic 5.0 - Second Edition (1997)(Microsoft Press).iso / Code / openpic.frm < prev    next >
Text File  |  1997-06-14  |  10KB  |  369 lines

  1. VERSION 5.00
  2. Begin VB.Form FOpenPictureFile 
  3.    BorderStyle     =   3  'Fixed Dialog
  4.    Caption         =   "Open Picture File"
  5.    ClientHeight    =   3276
  6.    ClientLeft      =   1392
  7.    ClientTop       =   2196
  8.    ClientWidth     =   7140
  9.    LinkTopic       =   "Form1"
  10.    ScaleHeight     =   3276
  11.    ScaleWidth      =   7140
  12.    Begin VB.CommandButton cmdNetwork 
  13.       Caption         =   "Network..."
  14.       Height          =   330
  15.       Left            =   5565
  16.       TabIndex        =   11
  17.       Top             =   945
  18.       Width           =   1380
  19.    End
  20.    Begin VB.ComboBox cboPicType 
  21.       Height          =   288
  22.       Left            =   240
  23.       Style           =   2  'Dropdown List
  24.       TabIndex        =   6
  25.       Top             =   2772
  26.       Width           =   2484
  27.    End
  28.    Begin VB.TextBox txtPicType 
  29.       BorderStyle     =   0  'None
  30.       Height          =   228
  31.       Left            =   204
  32.       TabIndex        =   5
  33.       Text            =   "*.bmp;*.wmf;*.ico;*.dib "
  34.       Top             =   384
  35.       Width           =   2448
  36.    End
  37.    Begin VB.CommandButton cmdCancel 
  38.       Cancel          =   -1  'True
  39.       Caption         =   "Cancel"
  40.       Height          =   330
  41.       Left            =   5565
  42.       TabIndex        =   4
  43.       Top             =   525
  44.       Width           =   1380
  45.    End
  46.    Begin VB.CommandButton cmdOK 
  47.       Caption         =   "OK"
  48.       Default         =   -1  'True
  49.       Height          =   330
  50.       Left            =   5565
  51.       TabIndex        =   3
  52.       Top             =   105
  53.       Width           =   1380
  54.    End
  55.    Begin VB.FileListBox filPic 
  56.       Height          =   1032
  57.       Left            =   180
  58.       TabIndex        =   2
  59.       Top             =   765
  60.       Width           =   2505
  61.    End
  62.    Begin VB.DirListBox dirPic 
  63.       Height          =   1536
  64.       Left            =   2940
  65.       TabIndex        =   1
  66.       Top             =   720
  67.       Width           =   2412
  68.    End
  69.    Begin VB.DriveListBox drvPic 
  70.       Height          =   288
  71.       Left            =   2928
  72.       TabIndex        =   0
  73.       Top             =   2760
  74.       Width           =   2496
  75.    End
  76.    Begin VB.Image imgSound 
  77.       Height          =   264
  78.       Left            =   6840
  79.       Top             =   3000
  80.       Visible         =   0   'False
  81.       Width           =   288
  82.    End
  83.    Begin VB.Image imgPic 
  84.       Height          =   1425
  85.       Left            =   5550
  86.       Top             =   1560
  87.       Width           =   1380
  88.    End
  89.    Begin VB.Label lbl 
  90.       Caption         =   "File Name:"
  91.       Height          =   228
  92.       Index           =   1
  93.       Left            =   192
  94.       TabIndex        =   12
  95.       Top             =   108
  96.       Width           =   2436
  97.    End
  98.    Begin VB.Label lbl 
  99.       Caption         =   "Directories:"
  100.       Height          =   216
  101.       Index           =   5
  102.       Left            =   2916
  103.       TabIndex        =   10
  104.       Top             =   108
  105.       Width           =   2436
  106.    End
  107.    Begin VB.Label lbl 
  108.       Caption         =   "List Files of Type:"
  109.       Height          =   312
  110.       Index           =   4
  111.       Left            =   204
  112.       TabIndex        =   9
  113.       Top             =   2436
  114.       Width           =   2508
  115.    End
  116.    Begin VB.Label lbl 
  117.       Caption         =   "Drives:"
  118.       Height          =   315
  119.       Index           =   3
  120.       Left            =   2925
  121.       TabIndex        =   8
  122.       Top             =   2415
  123.       Width           =   2430
  124.    End
  125.    Begin VB.Label lblPic 
  126.       Height          =   264
  127.       Left            =   2928
  128.       TabIndex        =   7
  129.       Top             =   384
  130.       Width           =   2436
  131.    End
  132. End
  133. Attribute VB_Name = "FOpenPictureFile"
  134. Attribute VB_GlobalNameSpace = False
  135. Attribute VB_Creatable = False
  136. Attribute VB_PredeclaredId = True
  137. Attribute VB_Exposed = False
  138. Option Explicit
  139.  
  140. ' Basic provides five constants, but we need six
  141. Private Enum EPictureType
  142.     ' vbPicTypeNone = 0
  143.     ' vbPicTypeBitmap = 1
  144.     ' vbPicTypeMetafile = 2
  145.     ' vbPicTypeIcon = 3
  146.     ' vbPicTypeEMetafile = 4
  147.     vbPicTypeCursor = 5
  148.     vbPicTypeWave = 6
  149. End Enum
  150.  
  151. Private sInitDir As String
  152. Private sFilePath As String     ' d:\path\
  153. Private sFileName As String     ' base.ext
  154. ' Full file spec is sFilePath & sFileName
  155. Private nsPicType As New Collection
  156. Private dxPic As Integer, dyPic As Integer
  157. Private ordMouse As Integer
  158. Private ordPicType As Integer
  159. Private afFilter As Long
  160.  
  161. ' FileTitle is read-only
  162. Friend Property Get FileTitle() As String
  163.     FileTitle = sFileName  ' FileTitle is actually filename
  164. End Property
  165.  
  166. Friend Property Get FileName() As String
  167.     If sFileName <> sEmpty Then
  168.         FileName = sFilePath & sFileName
  169.     ' Else (commented out because strings are empty by default)
  170.     '    FileName = sEmpty
  171.     End If
  172. End Property
  173.  
  174. Friend Property Let FileName(sFilePathA As String)
  175.     sFilePath = sFilePathA
  176. End Property
  177.  
  178. Friend Property Get InitDir() As String
  179.     InitDir = sInitDir
  180. End Property
  181.  
  182. Friend Property Let InitDir(sInitDirA As String)
  183.     sInitDir = sInitDirA
  184. End Property
  185.  
  186. Friend Property Get PicType() As Integer
  187.     PicType = ordPicType
  188. End Property
  189.  
  190. Friend Property Get FilterType() As EFilterPicture
  191.     FilterType = afFilter
  192. End Property
  193.  
  194. Friend Property Let FilterType(afFilterA As EFilterPicture)
  195.     afFilter = afFilterA
  196. End Property
  197.  
  198. Private Sub cboPicType_Change()
  199.     txtPicType.Text = nsPicType(cboPicType.ListIndex + 1)
  200. End Sub
  201.  
  202. Private Sub cboPicType_Click()
  203.     txtPicType.Text = nsPicType(cboPicType.ListIndex + 1)
  204.     filPic.Pattern = txtPicType.Text
  205. End Sub
  206.  
  207. Private Sub cmdCancel_Click()
  208.     sFileName = sEmpty
  209.     Unload Me
  210. End Sub
  211.  
  212. Private Sub cmdNetwork_Click()
  213.     Dim errOK As Long
  214.     errOK = WNetConnectionDialog(Me.hWnd, 1) ' WNTYPE_DRIVE
  215. End Sub
  216.  
  217. Private Sub cmdOK_Click()
  218.     Unload Me
  219. End Sub
  220.  
  221. Private Sub dirPic_Change()
  222.     filPic.Path = dirPic.Path
  223.     If filPic.ListCount > 0 Then
  224.         filPic.ListIndex = 0
  225.     End If
  226. End Sub
  227.  
  228. Private Sub drvPic_Change()
  229.     dirPic.Path = drvPic.Drive
  230. End Sub
  231.  
  232. Private Sub filPic_DblClick()
  233.     Unload Me
  234. End Sub
  235.  
  236. Private Sub filPic_PathChange()
  237.     sFilePath = NormalizePath(filPic.Path)
  238.     If filPic.ListCount > 0 Then filPic.ListIndex = 0
  239. End Sub
  240.  
  241. Private Sub filPic_Click()
  242.     sFileName = filPic.FileName
  243.     UpdateFile sFilePath & sFileName
  244. End Sub
  245.  
  246. Private Sub filPic_PatternChange()
  247.     If filPic.ListCount > 0 Then
  248.         filPic.ListIndex = 0
  249.     End If
  250. End Sub
  251.  
  252. Private Sub Form_Initialize()
  253.     BugMessage "Initialize"
  254. End Sub
  255.  
  256. Private Sub Form_Load()
  257.     BugMessage "Load"
  258.     If sInitDir <> sEmpty Then
  259.         dirPic.Path = NormalizePath(sInitDir)
  260.     Else
  261.         sInitDir = NormalizePath(dirPic.Path)
  262.     End If
  263.     dxPic = imgPic.Width
  264.     dyPic = imgPic.Height
  265.     With cboPicType
  266.         If afFilter = 0 Then afFilter = efpEverything
  267.         If afFilter And efpAllPicture Then
  268.             .AddItem "All Picture Files"
  269.             nsPicType.Add "*.bmp;*.dib;*.ico;*.wmf;*.cur"
  270.         End If
  271.         If afFilter And efpBitmap Then
  272.             .AddItem "Bitmaps (*.BMP;*.DIB)"
  273.             nsPicType.Add "*.bmp;*.dib"
  274.         End If
  275.         If afFilter And efpMetafile Then
  276.             .AddItem "Metafiles (*.WMF)"
  277.             nsPicType.Add "*.wmf"
  278.         End If
  279.         If afFilter And efpIcon Then
  280.             .AddItem "Icons (*.ICO)"
  281.             nsPicType.Add "*.ico"
  282.         End If
  283.         If afFilter And efpCursor Then
  284.             .AddItem "Cursors (*.CUR;*.ICO)"
  285.             nsPicType.Add "*.cur;*.ico"
  286.         End If
  287.         If afFilter And efpWave Then
  288.             .AddItem "Waves (*.WAV)"
  289.             nsPicType.Add "*.wav"
  290.         End If
  291.         If afFilter And efpAllFile Then
  292.             .AddItem "All Files (*.*)"
  293.             nsPicType.Add "*.*"
  294.         End If
  295.         If .ListCount Then .ListIndex = 0
  296.     End With
  297.     ' Save mouse pointer so we can restore
  298.     ordMouse = MousePointer
  299.     dirPic_Change
  300.     filPic_PathChange
  301.     filPic_Click
  302. End Sub
  303.  
  304. Private Sub UpdateFile(sFile As String)
  305.     MousePointer = ordMouse
  306.     With imgPic
  307.         .Visible = False
  308.         lblPic.Caption = sFile
  309.         .Stretch = False
  310.         If UCase$(Right$(sFile, 4)) = ".WAV" Then
  311.             sndPlaySound sFile, 0
  312.             .Picture = imgSound.Picture
  313.             .Visible = True
  314.             ordPicType = vbPicTypeWave
  315.             Exit Sub
  316.         End If
  317.         On Error Resume Next
  318.         .Picture = LoadPicture(sFile)
  319.         If Err Then Exit Sub
  320.         On Error GoTo 0
  321.         ordPicType = .Picture.Type
  322.         Select Case .Picture.Type
  323.         Case vbPicTypeIcon
  324.             If UCase$(Right$(sFile, 4)) = ".CUR" Then
  325.                 ordPicType = vbPicTypeCursor
  326.                 On Error Resume Next
  327.                 MousePointer = vbCustom
  328.                 MouseIcon = .Picture
  329.                 If Err = 0 Then Exit Sub
  330.                 On Error GoTo 0
  331.             End If
  332.         Case vbPicTypeBitmap
  333.             If ScaleX(.Picture.Width) > dxPic Then
  334.                 imgPic.Height = (dxPic / ScaleX(.Picture.Width)) * _
  335.                                 ScaleY(.Picture.Height)
  336.                 imgPic.Width = dxPic
  337.                 .Stretch = True
  338.             End If
  339.             If ScaleY(.Picture.Height) > dyPic Then
  340.                 imgPic.Width = (dyPic / ScaleY(.Picture.Height)) * _
  341.                                 ScaleX(.Picture.Width)
  342.                 imgPic.Height = dyPic
  343.                 .Stretch = True
  344.             End If
  345.             BugMessage "Palette: " & .Picture.hPal
  346.         Case vbPicTypeMetafile, vbPicTypeEMetafile
  347.             imgPic.Width = dxPic
  348.             imgPic.Height = dyPic
  349.             .Stretch = True
  350.         End Select
  351.         BugMessage "Type: " & .Picture.Type
  352.         BugMessage "Handle: " & .Picture.Handle
  353.         .Visible = True
  354.     End With
  355. End Sub
  356.  
  357. Private Sub Form_Terminate()
  358.     BugMessage "Terminate"
  359. End Sub
  360.  
  361. Private Sub Form_Unload(Cancel As Integer)
  362.     BugMessage "Unload"
  363. End Sub
  364.  
  365. Property Let Dummy(f As Boolean)
  366.     Debug.Print f
  367. End Property
  368.  
  369.